package com.higgins.eventtracking.client.health.record.rolling;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.higgins.eventtracking.client.FinanceTrackingService;
import com.higgins.eventtracking.client.FinanceTrackingServiceAsync;
import com.higgins.eventtracking.client.health.components.GenericChartPanel;
import com.higgins.eventtracking.client.health.components.GenericTabInterface;
import com.higgins.eventtracking.client.health.components.HealthOverviewChart;
import com.higgins.eventtracking.client.health.components.HealthOverviewChartListBox;
import com.higgins.eventtracking.client.health.fundamentals.AchievementTab;
import com.higgins.eventtracking.client.health.fundamentals.DigestionTab;
import com.higgins.eventtracking.client.health.fundamentals.FrameOfMindTab;
import com.higgins.eventtracking.client.health.fundamentals.GoalsTab;
import com.higgins.eventtracking.client.health.fundamentals.HolidaysTab;
import com.higgins.eventtracking.client.health.fundamentals.HourlyTab;
import com.higgins.eventtracking.client.health.fundamentals.HygieneTab;
import com.higgins.eventtracking.client.health.fundamentals.NegativeTab;
import com.higgins.eventtracking.client.health.fundamentals.SupportTab;
import com.higgins.eventtracking.client.health.fundamentals.TimetableTab;
import com.higgins.eventtracking.client.health.fundamentals.WellBeingTab;
import com.higgins.eventtracking.client.health.record.RulesTab;

public class RecordRollingTab extends VerticalPanel	implements GenericTabInterface		{
	private final FinanceTrackingServiceAsync financeTrackingService = GWT
											.create(FinanceTrackingService.class);
	private TabPanel tabPanel = new TabPanel();
    private AchievementRollingSubTab achievementTab = new AchievementRollingSubTab(this);
    private RulesRollingTab mentalHealthTab = new RulesRollingTab(this, "MentalHealthType");
    private RulesRollingTab experienceTab = new RulesRollingTab(this, "ExperienceType");
    private RulesRollingTab evidenceTab = new RulesRollingTab(this, "EvidenceType");
	private boolean firstRun = true;
	private boolean goals = false;
	private Integer tabIndex = null;
	private String tabTitle = null;
	
	@Override
	public Integer getTabIndex() {
		return tabIndex;
	}
	@Override
	public void setTabIndex(Integer index) {
		this.tabIndex = index;
	}
	@Override
	public String getTabTitle()	{
		return tabTitle;
	}
	@Override
	public void setTabTitle(String tabTitle)	{
		this.tabTitle = tabTitle;
	}

	public RecordRollingTab()	{	
		
	}
	
	public void addGoalsTab()	{
		addTabs();
	}
	public void update()	{
		if (firstRun)	
			initialise();
	}
	public void initialise()	{
		populateTabPanel();
		firstRun = false;
	}
	public void populateTabPanel()	{
		addTabs();
		add(tabPanel);
	}
	private void addTabs()	{
	    tabPanel.add(achievementTab, "Achievement");
	    achievementTab.update();
	    tabPanel.add(mentalHealthTab, "Mental Health");
		tabPanel.add(experienceTab, "Experience");
		tabPanel.add(evidenceTab, "Evidence");
		tabPanel.selectTab(0);
		tabPanel.addSelectionHandler(createSelectionHandler());		
	}
	public SelectionHandler<Integer> createSelectionHandler()	{
		SelectionHandler<Integer> selectionHandler = new SelectionHandler<Integer>() {
	        @Override
	        public void onSelection(SelectionEvent<Integer> integerSelectionEvent) {
                if (integerSelectionEvent.getSelectedItem() == 0)   {
                    achievementTab.update();
                }
                if (integerSelectionEvent.getSelectedItem() == 1)   {
                    mentalHealthTab.update();
                }
                if (integerSelectionEvent.getSelectedItem() == 2)   {
                    experienceTab.update();
                }
	            if (integerSelectionEvent.getSelectedItem() == 3)	{
	            	evidenceTab.update();
	            }
	        }
		};
		return selectionHandler;
	}
	@Override
	public void addChartPanel(GenericChartPanel chartPanel) {
		// TODO Auto-generated method stub
		
	}

}
